package com.itheima.bos.web.action.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheima.bos.domain.system.Role;
import com.itheima.bos.service.system.RoleService;
import com.itheima.bos.web.action.common.BaseAction;
import com.opensymphony.xwork2.ActionContext;

@Namespace("/")
@ParentPackage("json-default")
@Scope("prototype")
@Controller
public class RoleAction extends BaseAction<Role> {

	@Autowired
	private RoleService roleService;

	/*
	 * 查询所有的角色
	 */
	@Action(value = "role_list", results = { @Result(name = "success", type = "json") })
	public String list() {

		List<Role> roles = roleService.findAll();

		ActionContext.getContext().getValueStack().push(roles);

		return SUCCESS;
	}

	/*
	 * 保存角色表
	 */
	private String menuIds;
	private String[] permissionIds;

	public void setMenuIds(String menuIds) {
		this.menuIds = menuIds;
	}

	public void setPermissionIds(String[] permissionIds) {
		this.permissionIds = permissionIds;
	}

	@Action(value = "role_save", results = {
			@Result(name = "success", type = "redirect", location = "/pages/system/role.html") })
	public String save() {

		
		roleService.save(model, menuIds, permissionIds);

		return SUCCESS;
	}
}
